package com.cloudbroker.bcs.platform.ltb.middle.bizservice.impl;

import com.alibaba.fastjson.JSON;
import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.common.model.Pagination;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.FeedbackBizService;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.back.*;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.vo.FeedBackReply;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.vo.FeedbackAddForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.vo.FeedbackAdminForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.vo.FeedbackQueryForm;
import com.cloudbroker.bcs.platform.ltb.middle.entity.Feedback;
import com.cloudbroker.bcs.platform.ltb.middle.service.FeedBackService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by fangyf18371 on 2016/7/15.
 */
@Service
public class FeedbackBizServiceImpl implements FeedbackBizService {
    @Resource
    private FeedBackService feedBackService;

    @Override
    public FeedbackSubBack feedbackAdd(FeedbackAddForm feedbackAddForm) {
        String comment=feedbackAddForm.getContent_info();
        Feedback feedback = new Feedback();
        feedback.setContent(comment);
        feedback.setCreate_time(System.currentTimeMillis());
        feedback.setUpdate_time(System.currentTimeMillis());
        feedback.setFeedbacker(String.valueOf(feedbackAddForm.getUser().getUser_id()));
        feedback.setCompany_id(feedbackAddForm.getUser().getCompany_id());
        feedBackService.save(feedback);
        FeedbackSubBack feedbackSubBack=new FeedbackSubBack();
        return VOUtil.setSuccessResult(feedbackSubBack);
    }

    @Override
    public FeedbackList feedbackQuery(FeedbackQueryForm feedbackQueryForm) {
        Feedback feedback = new Feedback();
        feedback.setFeedbacker(String.valueOf(feedbackQueryForm.getUser().getUser_id()));
        feedback.setCompany_id(feedbackQueryForm.getUser().getCompany_id());
        Pagination page = new Pagination();
        page.setPage_no(feedbackQueryForm.getPage_no());
        page.setPage_size(feedbackQueryForm.getRequest_num());
        List<Feedback> feedbacks = feedBackService.queryWithPagination(feedback,page);
        List<FeedbackResult> feedbackResults = new ArrayList<>();
        for(Feedback tmp:feedbacks) {
            FeedbackResult feedResult = new FeedbackResult();
            feedResult.setContent_feedback(tmp.getContent());
            feedResult.setContent_info(tmp.getReply_content());
            feedbackResults.add(feedResult);
        }
        FeedbackList feedbackList = new FeedbackList();
        feedbackList.setData_list(feedbackResults);
        return VOUtil.setSuccessResult(feedbackList);
    }
}
